/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */


import { PathUtil } from '@ohos/hvigor';
import * as fse from 'fs-extra';
import * as path from 'path';

import { initByProject,initExecuteCommand,runHvigor } from '../src/common/common.js';

describe('test sync is valid',()=>{
  test.concurrent('sync output is valid',async ()=>{
    await initByProject('common-test',async (rootProject)=>{
      const command=initExecuteCommand({
        sync:true,
        tasks:[]
      });
      const result = await runHvigor(rootProject, command);
      expect(result.exitCode).toBe(0);
      const output: string = readSyncOutput();
      expect(JSON.parse(output)).toBeTruthy();
    });
  });
});

const readSyncOutput = (): string => {
  const syncOutputPath = path.resolve(PathUtil.getHvigorCacheDir(), 'outputs', 'sync', 'output.json');
  expect(fse.existsSync(syncOutputPath)).toBe(true);
  return fse.readFileSync(syncOutputPath, {encoding: 'utf-8'});
};
